package com.jms.web.controller.jms.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.jms.common.filter.utils.poi.ExcelUtil;
import com.jms.web.controller.jms.domain.Worksheet;
import com.jms.web.controller.jms.service.IWorksheetService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jms.common.annotation.Log;
import com.jms.common.core.controller.BaseController;
import com.jms.common.core.domain.AjaxResult;
import com.jms.common.enums.BusinessType;
import com.jms.common.core.page.TableDataInfo;

import java.util.List;

/**
 * 工单配置Controller
 * 
 * @author drx
 * @date 2024-09-25
 */
@RestController
@RequestMapping("/system/worksheet")
public class WorksheetController extends BaseController
{
    @Resource
    private IWorksheetService worksheetService;

    /**
     * 查询工单配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:list')")
    @GetMapping("/list")
    public TableDataInfo list(Worksheet worksheet)
    {
        startPage();
        List<Worksheet> list = worksheetService.selectWorksheetList(worksheet);
        return getDataTable(list);
    }

    /**
     * 导出工单配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:export')")
    @Log(title = "工单配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Worksheet worksheet)
    {
        List<Worksheet> list = worksheetService.selectWorksheetList(worksheet);
        ExcelUtil<Worksheet> util = new ExcelUtil<Worksheet>(Worksheet.class);
        util.exportExcel(response, list, "工单配置数据");
    }

    /**
     * 获取工单配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(worksheetService.selectWorksheetById(id));
    }

    /**
     * 新增工单配置
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:add')")
    @Log(title = "工单配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Worksheet worksheet)
    {
        return toAjax(worksheetService.insertWorksheet(worksheet));
    }

    /**
     * 修改工单配置
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:edit')")
    @Log(title = "工单配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Worksheet worksheet)
    {
        return toAjax(worksheetService.updateWorksheet(worksheet));
    }

    /**
     * 删除工单配置
     */
    @PreAuthorize("@ss.hasPermi('system:worksheet:remove')")
    @Log(title = "工单配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(worksheetService.deleteWorksheetByIds(ids));
    }
}
